const path = require('path')

const { app, BrowserWindow, ipcMain, screen, Menu, globalShortcut } = require("electron")
const { enable } = require('@/common/winUtils/enable');
const { encryptByDESModeCBCUtf8to64 } = require('@/common/utils/des')
const config = require('@/common/winUtils/config')
const file = require('@/common/utils/file')
const fs = require("fs");
let {ico} = config.getAppConfig()
let win = null
const setShopWin = {
  createWin: (success) =>{
    win = new BrowserWindow({
      width: 400,
      height: 400,
      title: "门店设置",
      resizable: false,
      maximizable: false,
      frame: false,
      transparent: true,
      modal: true,
      show: true,//是否显示界面 先设置否
      icon: ico,
      webPreferences: {
        partition: String(+new Date()),
        plugins: true, //是否支持插件
        nodeIntegration: true,
        contextIsolation: false,
        webViewTag: true,
        webSecurity: false,
        enableRemoteModule: true
      }
    });
    win.setMenu(null);

    globalShortcut.register('CommandOrControl+Shift+s', function () {
      win.webContents.openDevTools()
    })

    if (process.env.ENV == 'development') {
      win.loadURL(`${process.env.VUE_APP_WEB_DOMAIN}/setShop`, { extraHeaders: "pragma: no-cache\n" });
    } else {
      win.loadURL(`file://${path.join(__dirname, 'index.html')}#/setShop`);
    }
    enable(win);

    ipcMain.on("window-set-shop", (event, obj) => {
      file.configWrite(obj).then(() => {
        win.hide()
        win = null
        success(obj)
      })
    });
    win.once('ready-to-show', () => {
      win.show();
    });
    win.on("closed", () => {
      win = null;
    })
  }
}
module.exports = setShopWin;
